# Maintainer: Brett Cornwall <ainola@archlinux.org>
# Contributor: Luca Weiss
# Contributor: Michael Yang

pkgname=spdlog
pkgver=1.11.0
pkgrel=2
pkgdesc='Very fast, header-only/compiled, C++ logging library'
arch=('loong64' 'x86_64')
url='https://github.com/gabime/spdlog'
license=('MIT')
depends=('libfmt.so')
makedepends=('cmake')
options=(debug)
source=(
    "$pkgname-$pkgver.tar.gz::https://github.com/gabime/spdlog/archive/v$pkgver.tar.gz"
    "spdlog_fmt_external.patch"
)
provides=(
    'libspdlog.so'
)
sha256sums=('ca5cae8d6cac15dae0ec63b21d6ad3530070650f68076f3a4a862ca293a858bb'
            'a0eb34b7c6920f0db2587460071f53372663c191cdfe34bf5ea2704c309c745f')

prepare() {

    cd "$pkgname-$pkgver"
    patch -p1 <../spdlog_fmt_external.patch
}

build() {
    export CFLAGS+=" ${CPPFLAGS}"
    export CXXFLAGS+=" ${CPPFLAGS}"
    cmake -B build -S "$pkgname-$pkgver" \
        -DSPDLOG_BUILD_BENCH=OFF \
        -DSPDLOG_FMT_EXTERNAL=ON \
        -DSPDLOG_BUILD_SHARED=ON \
        -DSPDLOG_BUILD_TESTS=ON \
        -DCMAKE_BUILD_TYPE=None \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=lib \
        -Wno-dev
    make -C build
}

check() {
    make -C build test
}

package() {
    make -C build DESTDIR="$pkgdir" install
    install -Dm644 "$pkgname-$pkgver/LICENSE" -t "$pkgdir/usr/share/licenses/$pkgname/"
}
